# -*- coding: utf-8 -*-
# @Time : 2021/12/29 20:15
# @Author : Limusen
# @File : demo_baidu_login
import time

from selenium import webdriver

driver = webdriver.Chrome()

driver.get("https://sahitest.com/demo/iframesTest.htm")
driver.implicitly_wait(10)
# # 直接定位到link位置
# driver.find_element_by_xpath("/html/body/table/tbody/tr/td[1]/a[1]").click() #　发现脚本会报错　找不到这个元素

# 定位到iframe  当前是定位到左边框架
element = driver.find_element_by_xpath('//iframe[@style="float:left;margin:20px;"]')
driver.switch_to.frame(element)
time.sleep(2)
driver.find_element_by_xpath('/html/body/table/tbody/tr/td[1]/a[1]').click()

# 跳出框架
driver.switch_to.default_content()
time.sleep(2)
# 定位iframe框架中的iframe框架
element = driver.find_element_by_xpath('//div[@id="another"]/iframe')
driver.switch_to.frame(element)
time.sleep(2)
driver.find_element_by_xpath('/html/body/table/tbody/tr/td[1]/a[1]').click()

